﻿using AnesSystem.Models;
using AnesSystem.Services;
using AnesSystem.Util;
using Common;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{
    public class CruiseNurseCtrlViewModel:BaseViewModel<CruiseNurseCtrlViewModel>
    {
        #region Variables
        //巡航一
        private string _xh1 = "";
        //巡航二
        private string _xh2 = "";
        //巡航三
        private string _xh3 = "";


        private String _disCruiseNurse = "";
        //手术医生集合
        private List<AccountModel> _operDoctor1ModelList = new List<AccountModel>();

        #endregion

        #region Constructor
        public CruiseNurseCtrlViewModel()
        {
            if (PatientLink.AnesthesiaRecord.Xhhs1 != null && PatientLink.AnesthesiaRecord.Xhhs1.Length == 24) Xh1 =PatientLink.AnesthesiaRecord.Xhhs1;
            if (PatientLink.AnesthesiaRecord.Xhhs2 != null && PatientLink.AnesthesiaRecord.Xhhs2.Length == 24) Xh2 = PatientLink.AnesthesiaRecord.Xhhs2;
            if (PatientLink.AnesthesiaRecord.Xhhs3 != null && PatientLink.AnesthesiaRecord.Xhhs3.Length == 24) Xh3 =PatientLink.AnesthesiaRecord.Xhhs3;
        }

        #endregion

        #region Properties


        public string DisCruiseNurse
        {
            get
            {
                CruiseNurseDoctor();
                if (string.IsNullOrEmpty(_disCruiseNurse)) return "";
                return _disCruiseNurse;
            }

            set
            {
                _disCruiseNurse = value;
                RaisePropertyChanged("DisWashNurse");
            }
        }

        public string Xh1
        {
            get
            {
                return _xh1;
            }

            set
            {
                _xh1 = value;
            }
        }

        public string Xh2
        {
            get
            {
                return _xh2;
            }

            set
            {
                _xh2 = value;
            }
        }

        public string Xh3
        {
            get
            {
                return _xh3;
            }

            set
            {
                _xh3 = value;
            }
        }


        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods
        private void CruiseNurseDoctor()
        {
            _disCruiseNurse = "";
            if (PatientLink.AnesthesiaRecord.Xhhs1 != null && PatientLink.AnesthesiaRecord.Xhhs1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs1));
                if (a != null) _disCruiseNurse += a.TrueName ;
            }
            else
            {
                _disCruiseNurse += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xhhs1) ? "" : (PatientLink.AnesthesiaRecord.Xhhs1);
            }
            if (PatientLink.AnesthesiaRecord.Xhhs2 != null && PatientLink.AnesthesiaRecord.Xhhs2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs2));
                if (a != null) _disCruiseNurse += "," + a.TrueName;
            }
            else
            {
                _disCruiseNurse += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xhhs2) ? "" : ("," + PatientLink.AnesthesiaRecord.Xhhs2);
            }
            if (PatientLink.AnesthesiaRecord.Xhhs3 != null && PatientLink.AnesthesiaRecord.Xhhs3.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs3));
                if (a != null) _disCruiseNurse += "," + a.TrueName ;
            }
            else
            {
                _disCruiseNurse += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xhhs3) ? "" : ("," + PatientLink.AnesthesiaRecord.Xhhs3);
            }
        }

        #endregion

        #region Public/Protected Methods
        public void Keep()
        {

            Xh1 = Util.ExtensionMethods.CheckAccount(Xh1, "护士");
            PatientLink.AnesthesiaRecord.Xhhs1 = Xh1;
            Xh2 = Util.ExtensionMethods.CheckAccount(Xh2, "护士");
            PatientLink.AnesthesiaRecord.Xhhs2 = Xh2;
            Xh3 = Util.ExtensionMethods.CheckAccount(Xh3, "护士");
            PatientLink.AnesthesiaRecord.Xhhs3 = Xh3;

            PatientLinkService.Instance.AddUpdate(PatientLink);
            RaisePropertyChanged("DisCruiseNurse");
        }      

        #endregion

        #region EventHandlers

        #endregion
    }
}
